import requests
"""
发起接口请求，需要的必备要素：
1、请求方式
2、IP地址
3、端口号
4、接口的地址
5、请求参数（headers参数、body参数）
"""
# 发起post请求
# response = requests.post(url = "http://121.40.86.4:8899/adminapi/login",json={"account":"admin","pwd":"Aa010903!","key":"6826d94f95b0b","captchaType":"blockPuzzle","captchaVerification":""})
# 打印响应结果为json格式
# print(response.json())  # 结果是python的原始对象：字典
# 打印响应的url
# print(response.url)  # 请求的地址
# 打印响应的文本
# print(response.text) # 返回的是字符串
#打印响应的二进制
# print(response.content)
# 打印响应状态码
# print(response.status_code)
# 打印响应headers
# print(response.headers)
# 获取cookie
# print(response.cookies)
# 获取响应时间
# print(response.elapsed.microseconds)
# 获取响应头字符编码
# print(response.encoding)

# 发送get请求
# http://121.40.86.4:8899/adminapi/user/user_group/list?page=1&limit=15
"""
response = requests.get(url="http://121.40.86.4:8899/adminapi/user/user_group/list",headers={"Authori-zation":"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwd2QiOiIxZDg0OTY3ZTRhZmIwNmU3MTkwYjMzNmNiZDcyZGE4ZiIsImlzcyI6IjEyMS40MC44Ni40IiwiYXVkIjoiMTIxLjQwLjg2LjQiLCJpYXQiOjE3NDczNzY0NzQsIm5iZiI6MTc0NzM3NjQ3NCwiZXhwIjoxNzQ5OTY4NDc0LCJqdGkiOnsiaWQiOjEsInR5cGUiOiJhZG1pbiJ9fQ.xiv836FD89nDuFI5lMJgvp2eyjgmJnNfBe5PBo9aQEo"},params={"page":1,"limit":15})
# 打印响应结果
print(response.json())
"""

# 通过requests上传图片
# https://graph.baidu.com/upload
url = "https://graph.baidu.com/upload"
files = {
    "image":('33.jpg',open(r'C:\Users\Administrator\Desktop\img_v3_02mb_c50b215b-c013-4406-9c5a-c1e880a74a2g.jpg','rb'),"image/jpeg")
}
r = requests.post(url,files=files)
print(r.json())





"""
# response = response.json()
# print(response)
# 取出200
# print(response['status'])
# 取出token
# print(response['data']['token'])
# 取出/admin/index
# print(response['data']['menus'][0]['path'])
# 取出200
# 列表取出200
# list1 = [100,200,300]
# print(list1[1])
# 元组取出200
# tuple1 = (100,200,300)
# print(tuple1[1])
#字典取出200
# dict1 = {"s":100,"s1":200,"s2":300}
# print(dict1['s1'])
# response = {"status":200,"data":"xxxx"}
# print(response['status'])
"""